@tensorix/metahub 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +19 -6
  2. package/README.zh-CN.md +7 -2
  3. package/dist/cli.js +22843 -18308
  4. package/dist/cli.js.map +87 -66
  5. package/dist/core/blobs-core.d.ts +106 -0
  6. package/dist/core/blobs-core.d.ts.map +1 -0
  7. package/dist/core/blobs.d.ts +100 -0
  8. package/dist/core/blobs.d.ts.map +1 -0
  9. package/dist/core/cache.d.ts +18 -1
  10. package/dist/core/cache.d.ts.map +1 -1
  11. package/dist/core/compact.d.ts +43 -0
  12. package/dist/core/compact.d.ts.map +1 -0
  13. package/dist/core/config.d.ts +6 -3
  14. package/dist/core/config.d.ts.map +1 -1
  15. package/dist/core/context.d.ts +4 -4
  16. package/dist/core/context.d.ts.map +1 -1
  17. package/dist/core/crdt.d.ts +54 -8
  18. package/dist/core/crdt.d.ts.map +1 -1
  19. package/dist/core/databases.d.ts +22 -8
  20. package/dist/core/databases.d.ts.map +1 -1
  21. package/dist/core/db.d.ts +1 -27
  22. package/dist/core/db.d.ts.map +1 -1
  23. package/dist/core/documents.d.ts +28 -15
  24. package/dist/core/documents.d.ts.map +1 -1
  25. package/dist/core/driver.d.ts +25 -0
  26. package/dist/core/driver.d.ts.map +1 -0
  27. package/dist/core/history.d.ts +99 -11
  28. package/dist/core/history.d.ts.map +1 -1
  29. package/dist/core/hlc.d.ts +3 -3
  30. package/dist/core/hlc.d.ts.map +1 -1
  31. package/dist/core/index.d.ts +1 -0
  32. package/dist/core/index.d.ts.map +1 -1
  33. package/dist/core/indexing.d.ts +4 -4
  34. package/dist/core/indexing.d.ts.map +1 -1
  35. package/dist/core/integrity.d.ts +1 -1
  36. package/dist/core/integrity.d.ts.map +1 -1
  37. package/dist/core/node.d.ts +2 -2
  38. package/dist/core/node.d.ts.map +1 -1
  39. package/dist/core/properties.d.ts +10 -9
  40. package/dist/core/properties.d.ts.map +1 -1
  41. package/dist/core/records.d.ts +13 -8
  42. package/dist/core/records.d.ts.map +1 -1
  43. package/dist/core/resolve.d.ts +4 -4
  44. package/dist/core/resolve.d.ts.map +1 -1
  45. package/dist/core/schema-init.d.ts +68 -0
  46. package/dist/core/schema-init.d.ts.map +1 -0
  47. package/dist/core/schema.d.ts +1 -1
  48. package/dist/core/schema.d.ts.map +1 -1
  49. package/dist/core/search.d.ts +3 -3
  50. package/dist/core/search.d.ts.map +1 -1
  51. package/dist/core/sites-core.d.ts +95 -0
  52. package/dist/core/sites-core.d.ts.map +1 -0
  53. package/dist/core/sites.d.ts +8 -58
  54. package/dist/core/sites.d.ts.map +1 -1
  55. package/dist/core/sqlcols.d.ts +4 -0
  56. package/dist/core/sqlcols.d.ts.map +1 -0
  57. package/dist/core/sync/auth.d.ts +5 -3
  58. package/dist/core/sync/auth.d.ts.map +1 -1
  59. package/dist/core/sync/blob-routes.d.ts +12 -0
  60. package/dist/core/sync/blob-routes.d.ts.map +1 -0
  61. package/dist/core/sync/client.d.ts +13 -3
  62. package/dist/core/sync/client.d.ts.map +1 -1
  63. package/dist/core/sync/e2ee.d.ts +24 -0
  64. package/dist/core/sync/e2ee.d.ts.map +1 -0
  65. package/dist/core/sync/enroll.d.ts +21 -0
  66. package/dist/core/sync/enroll.d.ts.map +1 -0
  67. package/dist/core/sync/peers-routes.d.ts.map +1 -1
  68. package/dist/core/sync/peers.d.ts +84 -11
  69. package/dist/core/sync/peers.d.ts.map +1 -1
  70. package/dist/core/sync/protocol.d.ts +5 -0
  71. package/dist/core/sync/protocol.d.ts.map +1 -1
  72. package/dist/core/sync/publisher-lease.d.ts +8 -0
  73. package/dist/core/sync/publisher-lease.d.ts.map +1 -0
  74. package/dist/core/sync/routes.d.ts.map +1 -1
  75. package/dist/core/sync/server.d.ts +11 -0
  76. package/dist/core/sync/server.d.ts.map +1 -1
  77. package/dist/core/sync/sites-serve.d.ts.map +1 -1
  78. package/dist/core/sync/storage-s3-bun.d.ts +26 -0
  79. package/dist/core/sync/storage-s3-bun.d.ts.map +1 -0
  80. package/dist/core/sync/storage.d.ts +170 -0
  81. package/dist/core/sync/storage.d.ts.map +1 -0
  82. package/dist/db-worker.js +384 -0
  83. package/dist/index.js +17250 -13920
  84. package/dist/index.js.map +47 -32
  85. package/dist/metahub-sdk.js +1 -0
  86. package/dist/mh-runtime.js +1 -0
  87. package/dist/sqlite3.wasm +0 -0
  88. package/dist/sw.js +1 -0
  89. package/dist/webui/server/assets.d.ts +8 -1
  90. package/dist/webui/server/assets.d.ts.map +1 -1
  91. package/dist/webui/server/icons.d.ts +4 -0
  92. package/dist/webui/server/icons.d.ts.map +1 -0
  93. package/dist/webui/server/routes.d.ts.map +1 -1
  94. package/dist/webui.js +68 -62
  95. package/package.json +6 -1
package/README.md CHANGED
@@ -57,7 +57,7 @@ Output adapts to the audience: a terminal (human) gets tables / Markdown, a pipe
57
57
  import { openMetahub, createDatabase, createRecord, search } from "@tensorix/metahub";
58
58
  ```
59
59
 
60
- Platforms: `darwin-arm64` / `darwin-x64` / `linux-x64` / `linux-arm64` / `windows-x64`. Library API: see [CONTRIBUTING.md](./CONTRIBUTING.md).
60
+ Platforms: `darwin-arm64` / `darwin-x64` / `linux-x64` / `linux-arm64` / `windows-x64` / `windows-arm64`. Library API: see [CONTRIBUTING.md](./CONTRIBUTING.md).
61
61
 
62
62
  ## Sync across machines
63
63
 
@@ -77,11 +77,19 @@ Pair two devices once and they sync both ways on a timer — no need to run `mh
77
77
 
78
78
  `mh --server` serves a browser **WebUI** at `/` (browse and inline-edit tables, block-level WYSIWYG document editing, full-text search, manage agent sites). The same server also exposes:
79
79
 
80
- - `/api/*` — REST endpoints over your tables and documents.
80
+ - `/api/*` — REST endpoints over your tables and documents (read **and** write; hosted site pages call them same-origin).
81
81
  - `/docs` — auto-generated OpenAPI documentation.
82
- - `/sites/<name>/` — `mh site publish` hosts the HTML/CSS/JS an agent generates; pages call `/api/*` same-origin to read your data (a local mini-Supabase).
82
+ - `/sites/<name>/` — `mh site publish` hosts the HTML/CSS/JS an agent generates; pages call `/api/*` same-origin, or import the optional typed client at `/metahub-sdk.js` (a local mini-Supabase). Note the trust model: hosted pages are same-origin, so any published site effectively holds full hub access — publish only sites you or your agent authored.
83
83
 
84
- Requests are guarded by a single token (persisted in `~/.metahub`). The server binds `127.0.0.1` by default; only `--host 0.0.0.0` exposes it, and credentials travel as plaintext Bearer — put it behind a trusted network or TLS. Details in the [system-design docs](./docs/system-design/).
84
+ Requests are guarded by a single token (persisted in `~/.metahub`). The server binds `127.0.0.1` by default; only `--host 0.0.0.0` exposes it, and credentials travel as plaintext Bearer — put it behind a trusted network or TLS (a reverse proxy like Caddy / Tailscale Serve, or `--tls-cert`/`--tls-key` to terminate TLS directly). Details in the [system-design docs](./docs/system-design/).
85
+
86
+ ## Offline (PWA): the browser as a sync node
87
+
88
+ The WebUI is an installable PWA. Open **Settings → 离线副本** and this browser pairs with the server (an individually revocable credential), hydrates a **full local replica** (SQLite-in-OPFS running the same core), and from then on reads/writes go local with background `/sync` — on a weak network or fully offline you can still view **and edit everything**, including documents, tables, and hosted sites you never opened; changes merge block-level when connectivity returns. Notes:
89
+
90
+ - Needs HTTPS (service workers require a secure context) and a browser with OPFS (Safari 17+, Chrome, Firefox); unsupported browsers transparently stay plain online clients.
91
+ - On iPhone, add the app to the home screen — Safari evicts storage for regular tabs after ~7 days of disuse; home-screen apps are exempt.
92
+ - The first hydration must happen online; afterwards any tab (one leader per browser, others proxy to it) serves the data, and hosted site pages work offline too — reads and writes included.
85
93
 
86
94
  ## Command reference
87
95
 
@@ -100,10 +108,15 @@ Requests are guarded by a single token (persisted in `~/.metahub`). The server b
100
108
  | `mh doc read <id>` | Read body + version token (AI reads before editing) |
101
109
  | `mh doc edit <id> --old --new` | Anchored find-and-replace (`--replace-all` / `--if-match`) |
102
110
  | `mh doc append\|prepend <id> --body` | Append a block at the document head/tail |
111
+ | `mh doc history <id>` / `mh doc revert <id> --to <version>` | List a document's revisions / restore a past version (a new forward revision; `doc get --at <version>` previews; revert resurrects a deleted doc) |
112
+ | `mh record history <id> [--field <name>]` / `mh record revert <id> --to <version>` | Record edit history (per-revision field diffs, or one cell's value trail) / restore past cells (resurrects a deleted record) |
113
+ | `mh prop history <id>` / `mh prop revert <id> --to <version>` | Column definition history / schema rollback: restores the column **and** the cells its type-change/removal cleared, keeping user edits made since |
114
+ | `mh db activity [<id>] [--limit N]` | Table activity feed: every record's revisions merged newest-first, each with old→new cell values and a record-title snapshot (deleted records show their last title) |
103
115
  | `mh edit <id>` | Edit a document/record interactively in `$EDITOR` (for humans) |
104
116
  | `mh search <query>` | Full-text search (documents + records) |
105
- | `mh doctor` | Read-only health check: list integrity issues (orphan refs/cells, duplicate paths, doc cycles, name clashes) |
117
+ | `mh doctor` | Read-only health check: list integrity issues (orphan refs/cells, duplicate paths, doc cycles, name clashes) + oplog/disk stats |
106
118
  | `mh repair [--dry-run]` | Deterministic, idempotent repair of auto-fixable issues (changes replicate via oplog); `--dry-run` previews (same as doctor) |
119
+ | `mh compact [--keep <days>] [--dry-run]` | Prune oplog history older than the retention window (default 90d) + GC blobs + VACUUM. Local-only; current data untouched, older history collapses to a baseline |
107
120
  | `mh site create\|put\|publish\|list\|files\|rm\|delete` | Host static sites (HTML/CSS/JS) an agent generates, served by `--server` at `/sites/<name>/` |
108
121
  | `mh token [show\|refresh]` | Show/rotate the persisted server auth token (stored in `~/.metahub`, rotates at 30-day expiry by default) |
109
122
  | `mh completion <bash\|zsh\|fish>` | Print a completion script: `eval "$(mh completion zsh)"` |
@@ -112,7 +125,7 @@ Requests are guarded by a single token (persisted in `~/.metahub`). The server b
112
125
  | `mh config` | Configure the server and sync devices: no args opens an interactive wizard, `--flag` sets directly (`--host/--port/--sync-interval/--auto-sync`) |
113
126
  | `mh config peer code\|add\|list\|sync\|enable\|disable\|rm` | Multi-device pairing and management: generate a one-time code / pair / list / sync now / enable-disable / remove (also revokes the credential issued to the peer) |
114
127
  | `mh config grant list\|revoke` | List/revoke inbound sync credentials this machine issued (`revoke --token` accepts an exact value or prefix) |
115
- | `mh --server [--port] [--host] [--debug] [--token] [--sync-interval] [--no-auto-sync]` | Start the server: `/sync` (master token or pairing credential) + WebUI at `/` + `/api/*` REST + `/docs` (OpenAPI) + static sites `/sites/<name>/` + token exchange `/auth/token` + pairing `/api/pair`; a built-in timer auto-syncs paired peers |
128
+ | `mh --server [--port] [--host] [--debug] [--token] [--sync-interval] [--no-auto-sync] [--tls-cert --tls-key]` | Start the server: `/sync` (master token or pairing credential) + WebUI/PWA at `/` + `/api/*` REST + `/docs` (OpenAPI) + static sites `/sites/<name>/` + token exchange `/auth/token` + pairing `/api/pair`; a built-in timer auto-syncs paired peers; `--tls-*` serves https directly (PEM paths) |
116
129
 
117
130
  </details>
118
131
 
package/README.zh-CN.md CHANGED
@@ -57,7 +57,7 @@ mh doc append <ref> --body "追加段落" # 也有 prepend
57
57
  import { openMetahub, createDatabase, createRecord, search } from "@tensorix/metahub";
58
58
  ```
59
59
 
60
- 支持平台:`darwin-arm64` / `darwin-x64` / `linux-x64` / `linux-arm64` / `windows-x64`。库 API 详见 [CONTRIBUTING.md](./CONTRIBUTING.md)。
60
+ 支持平台:`darwin-arm64` / `darwin-x64` / `linux-x64` / `linux-arm64` / `windows-x64` / `windows-arm64`。库 API 详见 [CONTRIBUTING.md](./CONTRIBUTING.md)。
61
61
 
62
62
  ## 多机同步
63
63
 
@@ -100,10 +100,15 @@ mh sync http://a-host:7777
100
100
  | `mh doc read <id>` | 读正文 + version token(AI 改前先读) |
101
101
  | `mh doc edit <id> --old --new` | 锚定查找替换(`--replace-all` / `--if-match`) |
102
102
  | `mh doc append\|prepend <id> --body` | 在文档首/尾追加块 |
103
+ | `mh doc history <id>` / `mh doc revert <id> --to <version>` | 列出文档修订历史 / 恢复到某版本(回滚是一次新的正向修订;`doc get --at <version>` 预览;revert 可复活已删文档) |
104
+ | `mh record history <id> [--field <名>]` / `mh record revert <id> --to <version>` | 记录修改历史(逐修订字段 diff,或单字段值变迁)/ 恢复历史值(可复活已删记录) |
105
+ | `mh prop history <id>` / `mh prop revert <id> --to <version>` | 列定义历史 / schema 回滚:同时恢复列定义**和**被改类型/删列清掉的单元格,之后的用户编辑保留 |
106
+ | `mh db activity [<id>] [--limit N]` | 表级活动流:全表记录修订按时间倒序聚合,每条带字段级「旧值 → 新值」与记录标题快照(已删记录显示删除时的标题) |
103
107
  | `mh edit <id>` | 在 `$EDITOR` 中交互式编辑文档/记录(给人用) |
104
108
  | `mh search <query>` | 全文检索(文档 + 记录) |
105
- | `mh doctor` | 只读体检:列出逻辑完整性问题(孤儿引用/单元格、重复路径、文档环、重名等) |
109
+ | `mh doctor` | 只读体检:列出逻辑完整性问题(孤儿引用/单元格、重复路径、文档环、重名等)+ oplog/磁盘统计 |
106
110
  | `mh repair [--dry-run]` | 确定性、幂等修复可自动修的问题(改动随 oplog 复制);`--dry-run` 仅预览(等价 doctor) |
111
+ | `mh compact [--keep <天数>] [--dry-run]` | 清理保留窗口(默认 90 天)之外的 oplog 历史 + 回收无引用 blob + VACUUM。纯本地操作;当前数据不变,窗口外历史坍缩为基线(无法再回滚到更早版本) |
107
112
  | `mh site create\|put\|publish\|list\|files\|rm\|delete` | 托管 agent 生成的静态站点(HTML/CSS/JS),由 `--server` 在 `/sites/<name>/` serve 出去 |
108
113
  | `mh token [show\|refresh]` | 查看 / 轮换持久化的服务器鉴权 token(存于 `~/.metahub`,默认 30 天到期轮换) |
109
114
  | `mh completion <bash\|zsh\|fish>` | 打印补全脚本:`eval "$(mh completion zsh)"` |